package com.jj.service.impl;

import com.jj.dto.ProductTypeWithProductsDTO;
import com.jj.entity.Products;
import com.jj.mapper.ProductsMapper;
import com.jj.service.ProductService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductsMapper productsMapper;

    @Override
    public Products selectById(Integer productId) {
        return productsMapper.selectById(productId);
    }

    @Override
    public List<ProductTypeWithProductsDTO> selectAllTypesWithProducts() {
        return productsMapper.selectAllTypesWithProducts();
    }

    @Override
    @Transactional
    public int insertProduct(Products product) {
        return productsMapper.insertProduct( product);
    }

    @Override
    @Transactional
    public int updateProduct(Products product) {
        return productsMapper.updateProduct(product);
    }

    @Override
    @Transactional
    public int deleteById(Integer productId) {
        return productsMapper.deleteById(productId);
    }

    @Override
    public List<ProductTypeWithProductsDTO> selectAllProducts(@Param("productName") String productName) {
        return productsMapper.selectAllProducts(productName);
    }
}
